package com.qdlc.p2p.dal.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.qdlc.p2p.common.util.DateUtil;
import com.qdlc.p2p.dal.common.dao.jpa.BaseDaoImpl;
import com.qdlc.p2p.dal.common.model.jpa.QueryParam;
import com.qdlc.p2p.dal.dao.CooperationLoginDao;
import com.qdlc.p2p.dal.dto.CooperationLogin;

@Repository("cooperationLoginDao")
public class CooperationLoginDaoImpl extends BaseDaoImpl<CooperationLogin> implements CooperationLoginDao {

	/**
	 * 根据openId和type查询联合登录信息
	 * 
	 * @param openId
	 * @param type 合作登录类型
	 * @return
	 */
	@Override
	public CooperationLogin getCooperationLogin(String openId, int type) {
		QueryParam param = QueryParam.getInstance();
		param.addParam("openId", openId);
		param.addParam("type", type);
		return super.findByCriteriaForUnique(param);
	}

	/**
	 * 根据mesg和type查询联合登录信息
	 * 
	 * @param mesg 是否接收消息
	 * @param type 合作登录类型
	 * @return
	 */
	@Override
	public List<CooperationLogin> getListByTypeAndMesg(int type, boolean mesg) {
		QueryParam param = QueryParam.getInstance();
		param.addParam("mesg", mesg);
		param.addParam("type", type);
		return super.findByCriteria(param);
	}

	/**
	 * 新增联合登录信息
	 * 
	 * @param cooperation
	 */
	@Override
	public void addCooperationLogin(CooperationLogin cooperation) {
		cooperation.setAddTime(DateUtil.getNow());
		super.save(cooperation);
	}

	/**
	 * 修改联合登录信息
	 * 
	 * @param cooperation
	 */
	@Override
	public void updateCooperationLogin(CooperationLogin cooperation) {
		super.update(cooperation);
	}

}
